package com.toolenaar.socialiceThis;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.IBinder;
import android.util.Log;

public class LocationUpdaterService extends Service {
	public static final String LocationUpdaterService = 
		"com.toolenaar.socialiceThis.LocationUpdaterService.SERVICE";
	private Timer timer = new Timer();
	private static final int INTERVAL = 5000;
	//notification for when the service is started
	NotificationManager notifier;
	Notification notify;
	private static final int NOTIFY_1 = 0x1001;
	@Override
	public void onCreate() {
		// TODO Auto-generated method stub
		super.onCreate();
		startService();
			
	}

	private void startService(){
		//notify the user via the status bar
		notifier = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
		notify = new Notification(android.R.drawable.stat_notify_more,"Socialice This",System.currentTimeMillis());
		
		Intent toLaunch = new Intent(this,LocationUpdaterService.class);
		PendingIntent intentBack = PendingIntent.getActivity(getApplicationContext(), 0, toLaunch, 0);
		notify.setLatestEventInfo(getApplicationContext(), "Socialice This", "Gps updat service started",
				intentBack);
		
		notifier.notify(NOTIFY_1 ,notify);
		
		
		timer.scheduleAtFixedRate(new TimerTask(){
			public void run(){
				//do whatever here
				
			}
			
		}, 0, INTERVAL);
	}
	
	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		
		stopService();
		
	}
	private void stopService() {
		// TODO Auto-generated method stub
		if(timer != null){
			timer.cancel();
			timer = null;
		}
	}



	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

}
